package com.ui;

import android.content.ComponentName;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.RemoteException;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Switch;

import com.base.BaseContract;
import com.base.BaseSlideOutActivity;
import com.bean.BookBean;
import com.ddd.wandemo.IOnNewBookListener;
import com.ddd.wandemo.ITestAidlInterface;
import com.ddd.wandemo.R;
import com.util.LogUtil;
import com.util.ToastUtil;
import com.widget.MenuItemView;
import com.widget.MyCardView;
import com.widget.SelectDayLayout;

import java.util.ArrayList;
import java.util.List;

public class TestActivity extends BaseSlideOutActivity {
    @Override
    protected int setLayoutId() {
        return R.layout.activity_splash;
    }

    @Override
    protected BaseContract.RootPresenter initPresenter() {
        return null;
    }

    @Override
    protected void initView() {
        //menu RecyclerView
//        RecyclerView rvTest = findViewById(R.id.rv_test);
//        rvTest.setLayoutManager(new LinearLayoutManager(this));
//        List<MenuTextBean> list = new ArrayList<>();
//        for (int i =0;i<20;i++){
//            MenuTextBean bean = new MenuTextBean();
//            bean.setCount(0);
//            bean.setContent("abccc"+i);
//            bean.setTitle("hhhh"+i);
//            bean.setPrice(i+"");
//            list.add(bean);
//        }
//        TestRvAdapter testRvAdapter = new TestRvAdapter(this);
//        testRvAdapter.setData(list);
//        rvTest.setAdapter(testRvAdapter);

        final MenuItemView mit = findViewById(R.id.mit_mit);
        mit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mit.addCount();
            }
        });
        ImageView ivDecrease = mit.findViewById(R.id.iv_decrease);
        ivDecrease.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mit.decrease();
            }
        });


        /* ****************************** */
        final List<Integer> data = new ArrayList<>();
        for (int i = 1; i < 15; i++) {
            data.add(i);
        }
        SelectDayLayout sd = findViewById(R.id.sd_sd);
        sd.setViews(data);
        sd.setOnGetDateListener(new SelectDayLayout.onGetDateListener() {
            @Override
            public void getDate(int date) {
                ToastUtil.showToast(String.valueOf(date));
            }
        });


        final MyCardView myCardView = findViewById(R.id.my_cd);
        Switch swi = findViewById(R.id.swi);
        swi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    myCardView.setOnClickable(isChecked);
            }
        });


        FrameLayout fr = findViewById(R.id.fr);
        fr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtil.showToast("adfasf");
            }
        });
    }

    @Override
    protected void initEvent() {
//        Intent intent = new Intent(this,AidlTestService.class);
//        bindService(intent,conn, Context.BIND_AUTO_CREATE);
    }

    private ServiceConnection conn = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            ITestAidlInterface iTestAidlInterface = ITestAidlInterface.Stub.asInterface(service);
            try {
                iTestAidlInterface.show("123abc");
                BookBean bookBean = new BookBean();
                bookBean.setName("aaa");
                bookBean.setId(1);
                iTestAidlInterface.addBook(bookBean);
            } catch (RemoteException e) {
                e.printStackTrace();
            }

            try {
                iTestAidlInterface.registerListener(new IOnNewBookListener.Stub() {
                    @Override
                    public void onNewBookArrived(BookBean newBook) throws RemoteException {
                        LogUtil.d("ooooo--"+newBook.getName());
                    }
                });
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {

        }
    };

}
